import 'dart:convert';
import 'package:fluro/fluro.dart';
import 'package:mi_mang_flutter/model/daily_word_model.dart';
import 'package:mi_mang_flutter/page/collection/collection_page.dart';
import 'package:mi_mang_flutter/page/home/daily_picture_page.dart';
import 'package:mi_mang_flutter/page/public/daily_share_page.dart';
import 'package:mi_mang_flutter/routers/router_init.dart';

class HomeRouter implements IRouterProvider {
  /// 每日一图
  static String dailyPicture = "/daily/picture";

  /// 我的收藏
  static String collection = "/collection";

  /// 每日一图
  static String dailyShare = "/daily/share";

  @override
  void initRouter(FluroRouter router) {
    /// 每日一图
    router.define(
      dailyPicture,
      handler: Handler(handlerFunc: (_, params) => DailyPicturePage()),
    );

    /// 每日一图分享
    router.define(
      dailyShare,
      handler: Handler(handlerFunc: (_, params) {
        var modelJson = params['dialyModel']?.first;
        DailyWordModel? model;
        if (modelJson != null) {
          model = DailyWordModel.fromJson(jsonDecode(modelJson));
        }
        return DailySharePage(model: model);
      }),
    );

    /// 我的收藏
    router.define(
      collection,
      handler: Handler(handlerFunc: (_, params) => CollectionPage()),
    );
  }
}
